package com.yanfan.ledger.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.ledger.domain.DeviceLedger;
import com.yanfan.ledger.service.IDeviceLedgerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备基础信息Controller
 *
 * @author kerwincui
 * @date 2024-08-05
 */
@Api(tags = "设备台账基础信息")
@RestController
@RequestMapping("/iot/ledger")
public class DeviceLedgerController extends BaseController
{
    @Autowired
    private IDeviceLedgerService deviceLedgerService;

    /**
     * 查询设备基础信息列表
     */
    @ApiOperation("查询设备基础信息列表")
    @PreAuthorize("@ss.hasPermi('iot:ledger:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceLedger deviceLedger)
    {
        startPage();
        List<DeviceLedger> list = deviceLedgerService.selectDeviceLedgerList(deviceLedger);
        return getDataTable(list);
    }

    /**
     * 导出设备基础信息列表
     */
    @ApiOperation("导出设备基础信息列表")
    @PreAuthorize("@ss.hasPermi('iot:ledger:export')")
    @Log(title = "设备基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceLedger deviceLedger)
    {
        List<DeviceLedger> list = deviceLedgerService.selectDeviceLedgerList(deviceLedger);
        ExcelUtil<DeviceLedger> util = new ExcelUtil<DeviceLedger>(DeviceLedger.class);
        util.exportExcel(response, list, "设备基础信息数据");
    }

    /**
     * 获取设备基础信息详细信息
     */
    @ApiOperation("获取设备基础信息详细信息")
    @PreAuthorize("@ss.hasPermi('iot:ledger:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceLedgerService.selectDeviceLedgerById(id));
    }

    /**
     * 新增设备基础信息
     */
    @ApiOperation("新增设备基础信息")
    @PreAuthorize("@ss.hasPermi('iot:ledger:add')")
    @Log(title = "设备基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceLedger deviceLedger)
    {
        return toAjax(deviceLedgerService.insertDeviceLedger(deviceLedger));
    }

    /**
     * 修改设备基础信息
     */
    @ApiOperation("修改设备基础信息")
    @PreAuthorize("@ss.hasPermi('iot:ledger:edit')")
    @Log(title = "设备基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceLedger deviceLedger)
    {
        return toAjax(deviceLedgerService.updateDeviceLedger(deviceLedger));
    }

    /**
     * 删除设备基础信息
     */
    @ApiOperation("删除设备基础信息")
    @PreAuthorize("@ss.hasPermi('iot:ledger:remove')")
    @Log(title = "设备基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceLedgerService.deleteDeviceLedgerByIds(ids));
    }
}
